<template>
  <h1>EL-员工综合列表练习</h1>
  <el-form style="width: 500px;margin: 0 auto;" label-width="80">
    <el-form-item label="姓名">
      <el-input placeholder="请输入员工姓名" v-model="user.username"></el-input>
    </el-form-item>

    <el-form-item label="工资">
      <el-input placeholder="请输入员工工资" v-model="user.salary"></el-input>
    </el-form-item>

    <el-form-item label="岗位">
      <el-input placeholder="请输入员工岗位" v-model="user.job"></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="success" @click="tj">提交</el-button>
    </el-form-item>

    <el-table :data="useArr">
      <el-table-column type="index" label="编号" align="center" width="100px"></el-table-column>
      <el-table-column prop="username" label="姓名"></el-table-column>
      <el-table-column prop="salary" label="工资"></el-table-column>
      <el-table-column prop="job" label="岗位"></el-table-column>
      <el-table-column label="操作">

        <template #default="scope">
          <el-button type="danger" @click="del(scope.$index,scope.row)" l>删除</el-button>
        </template>

      </el-table-column>


    </el-table>


  </el-form>


</template>

<script setup>
import {ref} from "vue";
import {ElMessage} from "element-plus";

const user = ref({
  username: '',
  salary: '',
  job: ''
})
const useArr = ref([])

const tj = () => {
  if(user.value.username.trim()=='' || user.value.salary.trim()=='' || user.value.job.trim()==''){
    ElMessage.error('员工信息不能为空')
  }else{
    useArr.value.push(user.value)
    user.value = {  username: '',
      salary: '',
      job: ''}
  }
}
const del = (index, user) => {
  if (confirm(`你确定要删除${user.username}吗？`)) {
    ElMessage.success('删除成功');
    useArr.value.splice(index, 1)
  }
}
</script>


<style scoped>

</style>